﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<GabageFactory.Models.EventSearch>" %>
<%@ Import Namespace="System.Collections.Generic" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    事件处理列表
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%
        IEnumerable<EventRecordDetail> eventRecords = (IEnumerable<EventRecordDetail>)ViewData["eventRecords"];
        User user = (User) ViewData["user"];
        string[] types = (string[])ViewData["types"];
        string[] priorities = (string[])ViewData["priorites"];
    %>

    <%
        using(Html.BeginForm("Search", "Event", FormMethod.Get))
        {
    %>
    <%=Html.HiddenFor(model => model.PageNo) %>
    <div class="screen_area" style="width:1080px;">
        <div>
            <%if ((bool)ViewData["showFactory"])
                {%>
            请选择公司：<%= Html.DropDownList("FactoryID", ViewData["factories"] as List<SelectListItem>, "请选择公司", new { onchange = "showStacks();" })%>
            <span style="margin-left:20px"></span>
            <%
                }
                else
                {
            %>
            <%=Html.Hidden("FactoryID", Model.FactoryID)%>
            <%
                }
            %>
            请选择堆场/尾矿库：<span id="stackList"><%= Html.DropDownList("stackId", ViewData["stacksAndTailingponds"] as List<SelectListItem>, "请选择", new { onchange = "showStackDateRange();" })%></span></div>
        <div style="margin-top:15px">
            事件类别：
            <select name="Type">
                <option>请选择类别</option>
                <option value="1" <%if(Model.Type == 1){ %> selected="selected" <%} %>>输浆管</option>
                <option value="2" <%if(Model.Type == 2){ %> selected="selected" <%} %>>回水管</option>
                <option value="3" <%if(Model.Type == 3){ %> selected="selected" <%} %>>泵房</option>
                <option value="4" <%if(Model.Type == 4){ %> selected="selected" <%} %>>虹吸管</option>
                <option value="5" <%if(Model.Type == 5){ %> selected="selected" <%} %>>斜槽</option>
                <option value="6" <%if(Model.Type == 6){ %> selected="selected" <%} %>>截洪沟</option>
                <option value="7" <%if(Model.Type == 7){ %> selected="selected" <%} %>>初期堤</option>
                <option value="8" <%if(Model.Type == 8){ %> selected="selected" <%} %>>堆积坝</option>
                <option value="9" <%if(Model.Type == 9){ %> selected="selected" <%} %>>HDPE膜</option>
                <option value="10" <%if(Model.Type == 10){ %> selected="selected" <%} %>>山坡</option>
                <option value="11" <%if(Model.Type == 11){ %> selected="selected" <%} %>>底部导渗</option>
                <option value="12" <%if(Model.Type == 12){ %> selected="selected" <%} %>>堆体导渗</option>
                <option value="13" <%if(Model.Type == 13){ %> selected="selected" <%} %>>排洪设施</option>
                <option value="14" <%if(Model.Type == 14){ %> selected="selected" <%} %>>机械</option>
                <option value="15" <%if(Model.Type == 15){ %> selected="selected" <%} %>>其他</option>
            </select>
            <span style="margin-left:15px">事件级别：</span>
            <select name="Priority">
                <option>请选择优先级</option>
                <option value="1" <%if(Model.Priority == 1){ %> selected="selected" <%} %>>非常紧急</option>
                <option value="2" <%if(Model.Priority == 2){ %> selected="selected" <%} %>>紧急</option>
                <option value="3" <%if(Model.Priority == 3){ %> selected="selected" <%} %>>一般紧急</option>
                <option value="4" <%if(Model.Priority == 4){ %> selected="selected" <%} %>>普通</option>
                <option value="5" <%if(Model.Priority == 5){ %> selected="selected" <%} %>>无限制</option>
            </select>
            <span style="margin-left:15px">上报人：</span>
            <%= Html.DropDownList("RecorderId", ViewData["users"] as List<SelectListItem>, "请选择", new { style = "width:150px" })%>
        </div>
        <div style="margin-top:15px">
            <label>上报时间：</label>
            <span>
                <input type="radio" id="dateType1" name="dateType" checked="checked" value="1" onclick="resetDateType();" />
            </span>
            <select id="predefinedDate" name="predefinedDate" onclick="checkDateType(1);" style="width:80px;">
                <option value="0" <%if(Model.predefinedDate == 0){ %> selected="selected" <%} %>>不限</option>
                <option value="1" <%if(Model.predefinedDate == 1){ %> selected="selected" <%} %>>最近三天</option>
                <option value="7" <%if(Model.predefinedDate == 7){ %> selected="selected" <%} %>>最近一周</option>
                <option value="30" <%if(Model.predefinedDate == 0 || Model.predefinedDate == 30){ %> selected="selected" <%} %>>最近一月</option>
                <option value="90" <%if(Model.predefinedDate == 90){ %> selected="selected" <%} %>>最近三月</option>
            </select>
            
            <span style="margin-left:15px">
                <input type="radio" id="dateType2" name="dateType" value="2" />
            </span>
            <label>从</label> <input type="text" name="dateFrom" id="dateFrom" size="6" class="ipt_date" readonly="readonly" onclick="checkDateType(2);" /> <label>到</label> <input type="text" name="dateTo" id="dateTo" size="6" class="ipt_date" readonly="readonly"  onclick="checkDateType(2);" />
        </div>
        <div style="margin-top:15px">
            延续天数：
            <select name="Days">
                <option value="0" <%if(Model.Days == 0){ %> selected="selected" <%} %>>不限</option>
                <option value="1" <%if(Model.Days == 1){ %> selected="selected" <%} %>>5天以内</option>
                <option value="2" <%if(Model.Days == 2){ %> selected="selected" <%} %>>15天以内</option>
                <option value="3" <%if(Model.Days == 3){ %> selected="selected" <%} %>>1个月以内</option>
                <option value="4" <%if(Model.Days == 4){ %> selected="selected" <%} %>>3个月以内</option>
                <option value="5" <%if(Model.Days == 5){ %> selected="selected" <%} %>>半年以内</option>
                <option value="6" <%if(Model.Days == 6){ %> selected="selected" <%} %>>半年以上</option>
            </select>
            <input type="submit" onclick="return validateForm();" value="搜  索" />
        </div>
    </div>
    <%
        }
    %>

    <table id="spdata" cellpadding="4" cellspacing="0" class="com_from_table3" style="vertical-align:middle;width:1100px;">
        <tr>
            <th style="width:40px;">编号</th>
            <th style="width:140px;">事件名称</th>
            <th style="width:116px;">事件现场</th>
            <th>事件类别</th>
            <th>事件级别</th>
            <th>上报时间</th>
            <th>延续天数</th>
            <th>上报人</th>
            <th>处理进度</th>
            <th>&nbsp;</th>
        </tr>
        <%
          int i = 0;
          foreach (EventRecordDetail e in eventRecords)
          {
              i++;
        %>
        <tr>
            <td class="textCenter"><%=i %></td>
            <td style="padding-left:0.8em;"><%=Html.CutString(e.Name, 30, "...") %></td>
            <td style="padding-left:0.8em;"><%=e.StackName %></td>
            <td class="textCenter" style="width:60px;"><%=types[e.Type] %></td>
            <td class="textCenter" style="width:60px;"><%=priorities[e.Priority] %></td>
            <td class="textCenter" style="width:110px;"><%=e.OccurredDate.ToString("yyyy-MM-dd HH:mm") %></td>
            <td class="textCenter" style="width:56px;"><%=(DateTime.Now.Date - e.OccurredDate.Date).Days + 1%></td>
            <td style="padding-left:0.8em;"><%=e.UserName %></td>
            <td class="textCenter" style="width:60px;"><%=e.Progress %>%</td>
            <td class="textCenter" style="width:56px;">
            <%if (e.Status == 0 && user.RoleId == (int)RoleEnum.Recorder && e.CreateDate.Date == DateTime.Now.Date)
              { %>
              <%=Html.ActionLink("修改", "Edit", new { eventId = e.Id })%>
              <%=Html.ActionLink("删除", "Delete", new { eventId = e.Id })%>
            <%}
              else if (e.Status == 0 && user.RoleId == (int)RoleEnum.Recorder)
              {
            %>
            <%=Html.ActionLink("进程跟踪", "Track", new { eventId = e.Id })%>
            <%
               }else
              {
            %>
            <%=Html.ActionLink("进程详情", "Track", new { eventId = e.Id })%>
            <%
               }
            %>
            <%if (e.Status == 1 && user.RoleId == (int)RoleEnum.Auditor)
              { %>
              <%=Html.ActionLink("继续跟踪", "ReTrack", new { eventId = e.Id }, new { onclick = "return confirm('确定重新跟踪吗？');" })%>
              <%=Html.ActionLink("确认结束", "EndEvent", new { eventId = e.Id })%>
            <%}
            %>
            </td>
        </tr>
        <%} %>  
    </table>

    <%
        ViewData["currentPage"] = Model.PageNo;
        ViewData["totalPage"] = Model.TotalPage;
    %>
    <% Html.RenderPartial("Pagination", ViewData); %>

    <script type="text/javascript">
        $('#dateFrom').datepicker({ changeMonth: true, changeYear: true });
        $('#dateTo').datepicker({ changeMonth: true, changeYear: true });
        
        function checkDateType(dateType) {
            document.getElementById("dateType" + dateType).checked = true;
            if (dateType == 1) {
                resetDateType();
            }
        }

        function resetDateType() {
            document.getElementById("dateFrom").value = "";
            document.getElementById("dateTo").value = "";
        }

        function validateForm() {
            $('#PageNo').val(0);
            
            if (document.getElementById("dateType2").checked && document.getElementById("dateType2").value == 2)
            {
                var dateFrom = document.getElementById("dateFrom").value;
                if (dateFrom == 0 || dateFrom == "" || dateFrom == undefined) {
                    alert("请选择开始日期！");
                    document.getElementById("dateFrom").focus();
                    return false;
                }

                var dateTo = document.getElementById("dateTo").value;
                if (dateTo == 0 || dateTo == "" || dateTo == undefined) {
                    alert("请选择开始日期！");
                    document.getElementById("dateTo").focus();
                    return false;
                }
            }

            return true;
        }

        function showStacks() {
            var factoryId = document.getElementById("FactoryID").value;
            if (factoryId == "" || factoryId == 0) return;
            $.ajax({ 
                    type: "POST",
                    url: "<%=Url.Content("~/Modification/ListStacks") %>",
                    data: "factoryId=" + factoryId + "&showType=0",
                    success: function (data) { $("#stackList").html(data);}
            });
        }

        function showStackDateRange() {
            var id = document.getElementById("stackId").value;
            var vars = id.split("-");
            var showType = vars[0];
            var stackId = vars[1];
            $('#dateFrom').datepicker("destroy");
            $('#dateTo').datepicker("destroy");
            if (showType == 0) {
                $.ajax({ 
                        type: "POST",
                        url: "<%=Url.Content("~/Stack/GetDateRange") %>",
                        data: "stackId=" + stackId,
                        success: function (data) { 
                            var beginYear = data.BeginYear;
                            var endYear = data.EndYear;
                            $('#dateFrom').datepicker({ changeMonth: true, changeYear: true, reverseYearRange: 1, yearRange: beginYear + ":" + endYear });
                            $('#dateTo').datepicker({ changeMonth: true, changeYear: true, reverseYearRange: 1, yearRange: beginYear + ":" + endYear });
                        }
                });
            }
            else {
                $('#dateFrom').datepicker({ changeMonth: true, changeYear: true });
                $('#dateTo').datepicker({ changeMonth: true, changeYear: true });
            }
        }
    </script>
</asp:Content>
